﻿using Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace App.Forms
{
    public partial class Cashwithdraw : Form
    {
        public Cashwithdraw()
        {
            InitializeComponent();
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            Button btn=sender as Button;
            txtAmount.Text += btn.Text;
        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            txtAmount.Text = txtAmount.Text.Substring(0, txtAmount.Text.Length - 1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtAmount.Text = string.Empty;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnwithdraw_Click(object sender, EventArgs e)
        {
            TaskManager tm = new TaskManager();
            int amount=0;
            string msg="";
            txtmsg.ForeColor = System.Drawing.Color.Red;
            if (!int.TryParse(txtAmount.Text, out amount))
                msg = "Please Enter valid amount";
            else if (int.Parse(txtAmount.Text) % 5 != 0)
                msg = "Amount must be multiple of 5";
            else
                try
                {
                    msg = tm.WithDrawMoney(Model.CurrentSession.currentAccount, amount);
                    if (msg == "Success")
                    {
                        msg = "Withdrawal Successfully completed... \n Amount: " + amount;
                        txtmsg.ForeColor = System.Drawing.Color.Green;
                    }
                }
                catch (Exception)
                {

                    throw;
                }
            txtmsg.Visible = true;
            txtmsg.Text = msg;
            txtAmount.Text = string.Empty;
        }
    }
}
